package com.gsn.poker.play;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.gsn.poker.asset.ChatTexture;
import com.gsn.poker.game.MyPoker;
import com.gsn.poker.packet.PacketFactory;

public class ChatGroup extends Group {
	public ChatGroup(float wideParent) {

		int i;
		Image image = setImage(1);
		float pad = (wideParent - 6.0f * image.width) / 5;
		for (i = 0; i < 10; i++) {
			final int num = (i / 5) * 10 + (i % 5 + 1);
			final int num1 = 5 + (int) (i / 5) * 10 + (i % 5 + 1);
			Image bg = new Image(ChatTexture.inst().bgEmotion);
			Image bg1 = new Image(ChatTexture.inst().bgEmotion);
			Image icon = setImage(num);
			Image icon1 = setImage(num1);
			ChatTexture.inst().scaleActor(bg);
			ChatTexture.inst().scaleActor(bg1);
			addActor(bg);
			addActor(bg1);
			addActor(icon);
			addActor(icon1);
			bg.x = i * icon.width + i * pad;
			bg1.x = bg.x;
			bg1.y = icon.height * 1.2f;
			icon.x = bg.x;
			icon1.x = icon.x;
			icon.y = bg1.y;

			GsnImageButton mask = new GsnImageButton(ChatTexture.inst().iconMaskEmotion, ChatTexture.inst().iconMaskEmotionPress);
			ChatTexture.inst().scaleActor(mask);
			addActor(mask);
			mask.setClickListener(new ClickListener() {

				@Override
				public void click(Actor actor, float x, float y) {
					// TODO Auto-generated method stub
					MyPoker.game.playScreen.chatLayer.hide();
					MyPoker.client.send(PacketFactory.sendEmo(num));
				}
			});
			mask.x = icon.x;
			mask.y = icon.y;

			GsnImageButton mask1 = new GsnImageButton(ChatTexture.inst().iconMaskEmotion, ChatTexture.inst().iconMaskEmotionPress);
			ChatTexture.inst().scaleActor(mask1);
			addActor(mask1);
			mask1.setClickListener(new ClickListener() {

				@Override
				public void click(Actor actor, float x, float y) {
					// TODO Auto-generated method stub
					MyPoker.game.playScreen.chatLayer.hide();
					MyPoker.client.send(PacketFactory.sendEmo(num1));
				}
			});
			mask1.x = icon1.x;
			mask1.y = icon1.y;
		}

		width = 10 * image.width + 9 * pad;
		height = 2 * image.height + image.height * 0.2f;

	}

	public Image setImage(int id) {

		Image image;
		ChatTexture chatTexture = ChatTexture.inst();
		switch (id) {
		case 1:
			image = new Image(chatTexture.emo1);
			break;
		case 2:
			image = new Image(chatTexture.emo2);
			break;
		case 3:
			image = new Image(chatTexture.emo3);
			break;
		case 4:
			image = new Image(chatTexture.emo4);
			break;
		case 5:
			image = new Image(chatTexture.emo5);
			break;
		case 6:
			image = new Image(chatTexture.emo6);
			break;
		case 7:
			image = new Image(chatTexture.emo7);
			break;
		case 8:
			image = new Image(chatTexture.emo8);
			break;
		case 9:
			image = new Image(chatTexture.emo9);
			break;
		case 10:
			image = new Image(chatTexture.emo10);
			break;
		case 11:
			image = new Image(chatTexture.emo11);
			break;
		case 12:
			image = new Image(chatTexture.emo12);
			break;
		case 13:
			image = new Image(chatTexture.emo13);
			break;
		case 14:
			image = new Image(chatTexture.emo14);
			break;
		case 15:
			image = new Image(chatTexture.emo15);
			break;
		case 16:
			image = new Image(chatTexture.emo16);
			break;
		case 17:
			image = new Image(chatTexture.emo17);
			break;
		case 18:
			image = new Image(chatTexture.emo18);
			break;
		case 19:
			image = new Image(chatTexture.emo19);
			break;
		case 20:
			image = new Image(chatTexture.emo20);
			break;
		default:
			image = new Image(chatTexture.emo20);
			break;
		}
		chatTexture.scaleActor(image);
		return image;
	}
}
